package felix.rule.js.script;

import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.util.concurrent.ListenableFuture;
import felix.rule.data.msg.EngineMsg;

import javax.script.ScriptException;
import java.util.Set;

public interface ScriptEngine {

    /**
     * 执行js返回String结果
     *
     * @param msg
     * @return
     * @throws ScriptException
     */
    String executeToString(EngineMsg msg) throws ScriptException;

    /**
     * 执行js返回Boolean结果
     *
     * @param msg
     * @return
     * @throws ScriptException
     */
    boolean executeToBoolean(EngineMsg msg) throws ScriptException;

    /**
     * 执行js返回Set结果
     *
     * @param msg
     * @return
     * @throws ScriptException
     */
    Set<String> executeToSet(EngineMsg msg) throws ScriptException;

    /**
     * 执行js返回Json结果
     *
     * @param msg
     * @return
     * @throws ScriptException
     */
    JsonNode executeToJson(EngineMsg msg) throws ScriptException;

    /**
     * 异步执行js返回Json结果
     *
     * @param msg
     * @return
     * @throws ScriptException
     */
    ListenableFuture<String> executeToStringAsync(EngineMsg msg);

    /**
     * 异步执行js返回Boolean结果
     *
     * @param msg
     * @return
     * @throws ScriptException
     */
    ListenableFuture<Boolean> executeToBooleanAsync(EngineMsg msg);

    /**
     * 异步执行js返回Set结果
     *
     * @param msg
     * @return
     * @throws ScriptException
     */
    ListenableFuture<Set<String>> executeToSetAsync(EngineMsg msg);

    /**
     * 异步执行js返回Json结果
     *
     * @param msg
     * @return
     * @throws ScriptException
     */
    ListenableFuture<JsonNode> executeToJsonAsync(EngineMsg msg);

    /**
     * 销毁js引擎
     */
    void destroy();

}
